package top.yokey.android.base;

import android.app.Application;
import android.content.SharedPreferences;
import android.os.Build;

import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.tools.PictureFileUtils;

import java.util.HashMap;

import top.yokey.android.http.HttpHelp;
import top.yokey.android.http.MemberBean;

public class App extends Application {

    private static App app;
    private SharedPreferences sharedPreferences;
    private SharedPreferences.Editor editor;
    private MemberBean memberBean;//这是用户信息数据

    public static App get() {
        return app;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        //初始化Android系统自身的一些框架
        sharedPreferences = getSharedPreferences("wechat", MODE_PRIVATE);
        editor = sharedPreferences.edit();
        //第三方框架，应用自定义框架，系统通用的类，放在此处进行初始化
        //初始化httpHelp
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("model", Build.MODEL);
        hashMap.put("token", getSharedPreferences().getString("token", ""));
        HttpHelp.get().init(this, "http://192.168.56.1/api/", hashMap);
        PictureFileUtils.deleteCacheDirFile(get(), PictureMimeType.ofAll());
    }

    public SharedPreferences getSharedPreferences() {
        return sharedPreferences;
    }

    public SharedPreferences.Editor getEditor() {
        return editor;
    }

    public MemberBean getMemberBean() {
        return memberBean;
    }

    public void setMemberBean(MemberBean memberBean) {
        this.memberBean = memberBean;
    }
}
